package com.vf.admin.common.redis.session;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.DefaultCookieSerializer;
/** 
  * httpsession使用redis缓存的配置
 * 参考文章：https://blog.csdn.net/tang_jian_dong/article/details/90678744
  */
@Configuration
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 86400)  //session空闲有效期：24小时
public class SessionConfig {

    /**
          * 自定义返回给前端的Cookie的项目根路径
          * @return
          */
    @Bean
    public DefaultCookieSerializer defaultCookieSerializer() {
        DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
        defaultCookieSerializer.setCookiePath("/");
        return defaultCookieSerializer;
    }
}
